#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;

int n;
struct node
{
	int pos, t, d;
}a[N];

bool cmp(node& n1, node& n2)
{
	return n1.t * n2.d < n1.d * n2.t;
}

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++)
	{
		a[i].pos = i;
		cin >> a[i].t >> a[i].d;
	}
	sort(a + 1, a + 1 + n, cmp);
	LL ans = 0, time = 0;
	for(int i = 1;i <= n;i ++)
	{
		ans += 2 * time * a[i].d;
		time += a[i].t;
	}
	cout << ans << endl;
	return 0;
}